import pytest
import requests
from config import BASE_URL

test_data = [("admin", "HM_2023_test", 200, "成功"),
             ("", "HM_2023_test", 500, "错误"),
             ("admin", "", 500, "错误"),
             ]


class TestLogin:
    def test_login(self):
        for username, password, code, msg in test_data:
            # 每次循环重新获取验证码
            response = requests.get(BASE_URL + "/api/captchaImage")
            uuid = response.json()["uuid"]

            url = BASE_URL + "/api/login"
            data = {
                "username": username,
                "password": password,
                "code": "2",
                "uuid": uuid
            }
            response = requests.post(url, json=data)
            print(response.json())
            assert response.status_code == 200
            assert response.json()["code"] == code
            assert msg in response.json()["msg"]
